package com.tiandang.controller;

import com.lly835.bestpay.utils.JsonUtil;
import com.tiandang.service.PayService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import tiandang.core.error.BusinessException;

@RestController
@RequestMapping("/wechat/pay")
public class PayController {

  private final Logger log = LoggerFactory.getLogger(this.getClass());

  @Autowired
  private PayService payService;


  /**
   * 微信异步通知
   *
   * @param notifyData
   */
  @PostMapping("/notify")
  public String notify(@RequestBody String notifyData) throws BusinessException {
    log.info(" 微信异步通知:notifyData: {}" + JsonUtil.toJson(notifyData));
    payService.notify(notifyData);

    // 返回给微信处理结果
    String feedback = "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>";
    return feedback;
  }


}
